﻿using Dilon.Core.Service;
using Furion;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.EventBus;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dilon.Core
{
    public class LogSubscribeHandler: ISubscribeHandler
    {
        [SubscribeMessage("create:oplog")]
        public void CreateOpLog(string eventId, object payload)
        {
            SysLogOp log = (SysLogOp)payload;
            Scoped.Create((_, scope) =>
            {
                var services = scope.ServiceProvider;
                
                var _db = App.GetService<ISqlSugarClient>(services);   // services 传递进去

                _db.Insertable(log).ExecuteCommand();
            });


        }

        [SubscribeMessage("create:exlog")]
        public void CreateExLog(string eventId, object payload)
        {
            // 这里解析服务
            SysLogEx log = (SysLogEx)payload;
            Scoped.Create((_, scope) =>
            {
                var services = scope.ServiceProvider;

                var _db = App.GetService<ISqlSugarClient>(services);   // services 传递进去
                _db.Insertable(log).ExecuteCommand();
            });
           
        }

        [SubscribeMessage("create:vislog")]
        public void CreateVisLog(string eventId, object payload)
        {
            // 这里解析服务
            SysLogVis log = (SysLogVis)payload;
            Scoped.Create((_, scope) =>
            {
                var services = scope.ServiceProvider;

                var _db = App.GetService<ISqlSugarClient>(services);   // services 传递进去
                _db.Insertable(log).ExecuteCommand();
            });
        }
    }
}
